# Copyright 2024 The DLRover Authors. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(default_visibility = ["//visibility:public"])

cc_library(
    name = "tracing_data_h",
    hdrs = ["py_tracing_data.h"],
)

cc_library(
    name = "tracing",
    srcs = [
        "py_syshook.c",
        "py_tracing.c",
    ],
    hdrs = ["py_tracing.h"],
    deps = [
        ":tracing_data_h",
        "@python_lib//:python",
        "@uthash_archive//:uthash",
    ],
    alwayslink = True,
)

cc_library(
    name = "tracing_cpp",
    srcs = [
        "py_tracing_manager.cc",
    ],
    hdrs = ["py_tracing_manager.h"],
    deps = [
        ":tracing",
        "//xpu_timer/common:logging",
        "//xpu_timer/common:util",
    ],
    alwayslink = True,
)

cc_library(
    name = "tracing_lib_loader",
    srcs = [
        "py_tracing_loader.cc",
    ],
    hdrs = [
        "py_tracing_loader.h",
    ],
    deps = [
        ":tracing_data_h",
        "//xpu_timer/common:logging",
        "//xpu_timer/common:xpu_timer",
    ],
)

cc_binary(
    name = "libpy_tracing.so",
    copts = [
        "-std=c++17",
        "-fPIC",
    ],
    linkopts = [
        "-shared",
    ],
    linkshared = 1,
    deps = [
        ":tracing",
        ":tracing_cpp",
        ":tracing_data_h",
    ],
)
